package com.likersai.funa.service.impl;

import com.likersai.funa.dao.FundProductDao;
import com.likersai.funa.pojo.dto.param.customer.CustomerQueryParam;
import com.likersai.funa.pojo.dto.param.fundProduct.ProductQueryParam;
import com.likersai.funa.pojo.dto.req.fundProduct.FundProductQueryReq;
import com.likersai.funa.pojo.entity.Customer;
import com.likersai.funa.pojo.entity.FundProduct;
import com.likersai.funa.pojo.vo.model.Page;
import com.likersai.funa.service.FundProductService;
import com.likersai.funa.util.PageUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 基金产品表(FundProduct)表服务实现类
 *
 * @author sun.ye
 * @since 2021-07-19 20:03:47
 */
@Service("fundProductService")
public class FundProductServiceImpl implements FundProductService {
    @Resource
    private FundProductDao fundProductDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public FundProduct queryById(Long id) {
        return this.fundProductDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     *
     * @param req @return 对象列表
     * @return
     */
    @Override
    public Page<FundProduct> queryPage(FundProductQueryReq req) {
        ProductQueryParam pageParam = req.toParam();
        PageUtils.setParamFromReq(req.getPage(),pageParam.getPage());
        List<FundProduct> result = fundProductDao.queryList(pageParam);
        int recordsCount = fundProductDao.queryPageCount(pageParam);
        return PageUtils.getPage(result, recordsCount, req.getPage());

    }

    /**
     * 新增数据
     *
     * @param fundProduct 实例对象
     * @return 实例对象
     */
    @Override
    public FundProduct insert(FundProduct fundProduct) {
        this.fundProductDao.insert(fundProduct);
        return fundProduct;
    }

    /**
     * 修改数据
     *
     * @param fundProduct 实例对象
     * @return 实例对象
     */
    @Override
    public FundProduct update(FundProduct fundProduct) {
        this.fundProductDao.update(fundProduct);
        return this.queryById(fundProduct.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.fundProductDao.deleteById(id) > 0;
    }
}